<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <%-- 页头 --%>
    <title>添加视频分类 - ReadJava教程</title>
    <%@include file="../common/head.jsp" %>
    <link rel="stylesheet" href="/resources/editor/css/editormd.min.css"/>
</head>
<body>
<div class="wrapper">

    <%-- 导航 --%>
    <%@include file="manage-header.jsp" %>

    <%-- 侧边栏 --%>
    <%@include file="manage-sidebar.jsp" %>

    <div class="main-panel">
        <div class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <div class="card-title">新增视频分类</div>
                            </div>
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>视频标题</label>
                                            <input type="text" name="acTitle" class="form-control input-square vcTitle">
                                        </div>
                                        <div class="form-group">
                                            <label>视频图标</label>
                                            <input type="text" name="acIcon" class="form-control input-square vcIcon">
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>视频价格</label>
                                            <input type="text" name="acIcon" class="form-control input-square vcPrice">
                                        </div>
                                        <div class="form-group text-center">
                                            <label class="form-radio-label">
                                                <input class="form-radio-input vcState" type="radio"
                                                       name="acState" value="0" checked>
                                                <span class="form-radio-sign">启用分类</span>
                                            </label>
                                            <label class="form-radio-label">
                                                <input class="form-radio-input vcState" type="radio"
                                                       name="acState" value="1">
                                                <span class="form-radio-sign">禁用分类</span>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label>视频目录</label>
                                            <div id="test-editormd">
                                                <textarea style="display:none;" id="textContent"
                                                          name="vcContent"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="card-action text-center">
                                <button type="button" class="btn btn-info btn-success" id="addVcBtn">
                                    新增分类
                                </button>
                                <button type="button" class="btn btn-info btn-danger"
                                        onclick="window.location.href='/manage/video/category/list'">
                                    返回管理
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<%-- 页脚 --%>
<%@include file="../common/footer.jsp" %>

</div>
</body>

<script src="/resources/assets/js/core/jquery.3.2.1.min.js"></script>
<script src="/resources/editor/lib/marked.min.js"></script>
<script src="/resources/editor/lib/prettify.min.js"></script>
<script src="/resources/editor/lib/raphael.min.js"></script>
<script src="/resources/editor/lib/underscore.min.js"></script>
<script src="/resources/editor/lib/sequence-diagram.min.js"></script>
<script src="/resources/editor/lib/flowchart.min.js"></script>
<script src="/resources/editor/lib/jquery.flowchart.min.js"></script>
<script src="/resources/editor/editormd.min.js"></script>
<script>
    var testEditor;
    $(function () {
        testEditor = editormd("test-editormd", {
            height: 600,
            htmlDecode: "video",  // 你可以过滤标签解码
            syncScrolling: "single",
            path: "/resources/editor/lib/",
            saveHTMLToTextarea: true,
            imageUpload: true,
            imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
            imageUploadURL: "/ftp/upload",
        });

        $("#addVcBtn").on("click", function () {
            var vcTitle = $(".vcTitle").val();
            var vcPrice = $(".vcPrice").val();
            var vcIcon = $(".vcIcon").val();
            var vcState = $('.vcState:checked').val();
            var vcContent = testEditor.getMarkdown();
            if (vcTitle != null && vcTitle.length != 0) {
                if (vcPrice != null && vcPrice.length != 0) {
                    if (vcIcon != null && vcIcon.length != 0) {
                        if (vcState != null && vcState.length != 0) {
                            if (vcContent != null && vcContent.length != 0) {
                                $.ajax({
                                    type: "POST",
                                    url: "/manage/video/category/add",
                                    data: {
                                        vcTitle: vcTitle,
                                        vcPrice: vcPrice,
                                        vcIcon: vcIcon,
                                        vcState: vcState,
                                        vcContent: vcContent
                                    },
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.status == 200) {
                                            alert(data.message);
                                            window.location.reload();
                                        }
                                    },
                                    error: function () {
                                        alert("操作失败：Ajax新增错误");
                                    }
                                });
                            } else {
                                alert("操作失败：视频目录不能为空");
                            }
                        } else {
                            alert("操作失败：未设置视频状态");
                        }
                    } else {
                        alert("操作失败：视频图标不能为空");
                    }
                } else {
                    alert("操作失败：视频价格不能为空");
                }
            } else {
                alert("操作失败：视频标题不能为空");
            }
        });
    });
</script>
</html>